package com.fmsz.xmly.activitys.classify;

import android.content.Intent;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.fmsz.xmly.R;

public class ClassifyFocusImageActivity extends AppCompatActivity {

    private Toolbar toolbar;
    private ActionBar actionBar;
    private String htmlUrl;
    private WebView webView;
    private ProgressBar progressBar;
    private TextView title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_classify_focus_image);
        Intent intent = getIntent();
        if (intent!=null) {
            htmlUrl = intent.getStringExtra("htmlUrl");
        }
        initView();
    }

    private void initView() {
        toolbar = ((Toolbar) findViewById(R.id.toolbar_top_list_focus));
        title = ((TextView) toolbar.findViewById(R.id.title_toolbar));
        setSupportActionBar(toolbar);
        actionBar = getSupportActionBar();
        actionBar.setDisplayShowTitleEnabled(false);
        progressBar = ((ProgressBar) findViewById(R.id.progressbar_top_list));
        webView = ((WebView) findViewById(R.id.webView));
        webView.setWebChromeClient(new WebChromeClient(){
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                progressBar.setProgress(newProgress);
                if (newProgress>=100) {
                    progressBar.setVisibility(View.GONE);
                }
            }
        });
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                return false;
            }
        });
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        if (htmlUrl!=null) {
            webView.loadUrl(htmlUrl);
        }
    }
}
